package com.example.environment.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.environment.pojo.Supervisor;
import com.example.environment.pojo.mapper.SupervisorMapper;
import com.example.environment.service.SupervisorService;
import com.example.environment.tools.common.ResultMsg;
import org.springframework.stereotype.Service;

@Service
public class SupervisorServiceImpl extends ServiceImpl<SupervisorMapper, Supervisor> implements SupervisorService {
    public ResultMsg saveByUnique(Supervisor Supervisor){
        QueryWrapper<Supervisor> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("phone", Supervisor.getPhone());
        Supervisor supervisor = getOne(queryWrapper, false); // 调用 getOne 方法
        if (supervisor != null) {
            return ResultMsg.ExistPhone();
        } else {
            if(save(Supervisor)){
                // 调用 save 方法
                return ResultMsg.successOp("注册成功");
            }else{
                return ResultMsg.failOp("注册失败");
            }
        }
    }
}
